/*
 * @Author       : xiangmin
 * @File         : 脱敏函数(手机/昵称/身份证)
 * @Date         : 2023-07-27 22:42:36
 * @LastEditors  : xiangmin
 * @LastEditTime : 2023-07-28 09:57:09
 */

class Mask {
	phone(phoneNum: string | number): string {
		phoneNum = phoneNum + ''
		return phoneNum.replace(/(\d{3})\d+(\d{4})/, '$1****$2')
	}

	name(nickName: string): string {
		if (!nickName) {
			return ''
		}
		let newName = ''
		if (nickName.length === 2) {
			newName = `${nickName[0]}*`
		} else if (nickName.length > 2) {
			let char = '*'
			char = char.repeat(3)
			newName = `${nickName[0]}${char}${nickName[nickName.length - 1]}`
		}
		return newName
	}

	idCard(idCardNum: string | number): string {
		idCardNum = idCardNum + ''
		return idCardNum.replace(/(\d{6})\d+(\d{4})/, '$1******$2')
	}
}

export default new Mask()
